<template>
  <view class="container">
    <view class="tab-box">
      <view class="top-tab">
        <button :class="tab_index == 1 ? 'select' : ''" @click="tab_index = 1">
          好友邀请
        </button>
        <button :class="tab_index == 2 ? 'select' : ''" @click="tab_index = 2">
          邀请记录
        </button>
        <button :class="tab_index == 3 ? 'select' : ''" @click="tab_index = 3">
          规则
        </button>
      </view>
    </view>

    <view class="tab_1" v-if="tab_index == 1">
      <view class="hb">
        <image
          class="bg"
          :src="$img_path('/pagesMine/50.png')"
          mode="scaleToFill"
        ></image>
        <image
          v-if="qrcode"
          @click="uploadQrcode"
          class="qrcode"
          :src="qrcode"
          mode="scaleToFill"
        ></image>
        <image
          v-if="!qrcode"
          @click="uploadQrcode"
          class="qrcode"
          :src="$img_path('/pagesMine/59.png')"
          mode="scaleToFill"
        ></image>
      </view>
      <view class="shareBox hb_b">
        <view class="title">
          <text>分享至</text>
        </view>
        <view class="box">
          <view class="item" @click="saveCanvasImg()">
            <image
              :src="$img_path('/pagesMine/53.png')"
              mode="widthFix"
            ></image>
            <text>保存图片</text>
          </view>
          <view class="item" @click="shareClick('WXSceneSession')">
            <image
              :src="$img_path('/pagesMine/51.png')"
              mode="widthFix"
            ></image>
            <text>微信好友</text>
            <!-- #ifdef MP-WEIXIN -->
            <button open-type="share"></button>
            <!-- #endif -->
          </view>
          <view class="item" @click="shareClick('WXSceneTimeline')">
            <image
              :src="$img_path('/pagesMine/52.png')"
              mode="widthFix"
            ></image>
            <text>朋友圈</text>
          </view>
        </view>
      </view>

      <view class="jiantou" v-if="pengyouquan" @click="pengyouquan = false">
        <image
          :style="{ top: 5 + 'px', right: jWidth + 'px' }"
          :src="$img_path('/course/jian.png')"
          mode="widthFix"
        ></image>
        <view class="text"> 请点击这里 </view>
      </view>
    </view>

    <view class="tab_2" v-if="tab_index == 2">
      <view class="item" v-for="(item, i) in 10" :key="i">
        <view class="left">
          <image :src="$img_path('/mall/5.png')" mode="aspectFill"></image>
          <view class="user">
            <view class="name"> 昵称昵称 </view>
            <view class="phoneNumber"> 12345678910 </view>
          </view>
        </view>
        <view class="right">
          <view class="time"> 2024-05-23 </view>
          <view class="status"> 注册成功 </view>
        </view>
      </view>
    </view>

    <view class="tab_3" v-if="tab_index == 3">
      内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容
    </view>
  </view>
</template>

<script>
import { upload } from "@/utils/api/public.js";
export default {
  data() {
    return {
      jWidth: this.jWidth - 30,
      tab_index: 1,
      pengyouquan: false,
      // 二维码
      qrcode: "",
    };
  },

  //分享朋友圈
  onShareTimeline(res) {
    return {
      title: "朋友圈", //分享的标题
      imageUrl: "", //展示的图片，这里是本地路径的写法，也可以写http或https开头的图片路径
      query: "from=shareTimeline", //页面打开的传参
    };
  },
  // 分享到好友
  onShareAppMessage(res) {
    return {
      title: "好友", //分享的标题
      imageUrl: "", //展示的图片，这里是本地路径的写法，也可以写http或https开头的图片路径
      path: "/pages/index/index", //点击链接后跳转的页面，可以带参数
    };
  },
  onLoad(options) {
    if (options.tab_index) {
      this.tab_index = options.tab_index;
    }
  },
  methods: {
    shareClick(text) {
      if (text == "WXSceneTimeline") {
        console.log("-------");
        this.pengyouquan = true;
      }
    },
    // 上传二维码
    uploadQrcode() {
      let that = this;
      uni.chooseImage({
        count: 1, //默认9
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
        sourceType: ["album"], //从相册选择
        success: function (res) {
          let file = res.tempFilePaths[0];
          upload({ file }).then((data) => {
            let qrcode = data.data.fullurl;
            that.$set(that, "qrcode", qrcode);
          });
        },
      });
    },
    // 保存图片
    saveCanvasImg() {
      uni.canvasToTempFilePath({
        canvasId: "myCanvas",
        success: function (res) {
          uni.saveImageToPhotosAlbum({
            filePath: res.tempFilePath,
            success: function (res) {
              uni.showToast({
                title: "保存成功",
                icon: "none",
              });
            },
          });
        },
      });
    }
  },
};
</script>
<style>
page {
  background-color: #ffffff;
}
</style>
<style lang="scss" scoped>
.container {
  padding: 0rpx 22rpx;
  .tab-box {
    position: sticky;
    top: 0rpx;
    padding-top: 20rpx;
    background-color: #ffffff;
    .top-tab {
      width: 100%;
      display: flex;
      height: 84rpx;
      border-radius: 84rpx;
      border: 2rpx solid #e72a2a;
      overflow: hidden;
      button {
        flex: 1;
        font-weight: 400;
        font-size: 32rpx;
        color: #e72a2a;
        line-height: 84rpx;
        border-radius: 0;
        background-color: #ffffff;
        &:first-child {
          border-right: 2rpx solid #e72a2a;
        }
        &:last-child {
          border-left: 2rpx solid #e72a2a;
        }
        &.select {
          color: #ffffff;
          background-color: #e72a2a;
        }
      }
    }
  }

  .tab_1 {
    .hb {
      width: 706rpx;
      height: 918rpx;
      margin: 40rpx auto 0;
      position: relative;
      .bg {
        width: 100%;
        height: 100%;
      }
      .qrcode {
        position: absolute;
        bottom: 26rpx;
        left: 50%;
        transform: translateX(-50%);
        width: 252rpx;
        height: 252rpx;
      }
    }

    .shareBox {
      padding: 172rpx 0 0;
      // background: #F5F5F5;

      .title {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;

        text {
          font-weight: bold;
          font-size: 32rpx;
          color: #000000;
          line-height: 44rpx;
        }

        image {
          width: 48rpx;
          height: 48rpx;
          position: absolute;
          right: 30rpx;
          top: 0;
        }
      }

      .box {
        padding: 70rpx 30rpx 38rpx;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-around;

        .item {
          display: flex;
          flex-direction: column;
          align-items: center;
          image {
            width: 88rpx;
            height: 88rpx;
          }

          text {
            font-weight: 400;
            font-size: 26rpx;
            color: #1f2228;
            line-height: 36rpx;
            text-align: center;
          }

          position: relative;

          button {
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            opacity: 0;
          }
        }
      }

      &.coupon {
        background-color: #ffffff;
      }

      .coupon-box {
        padding: 70rpx 30rpx 38rpx;

        .item {
          width: 100%;
          height: 186rpx;
          position: relative;

          &:not(:last-child) {
            margin-bottom: 30rpx;
          }

          & > image.bg {
            width: 100%;
            height: 100%;
          }

          .c_num {
            position: absolute;
            left: 40rpx;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            align-items: center;

            .price {
              font-weight: bold;
              font-size: 48rpx;
              color: #fd845c;
              line-height: 66rpx;

              text {
                font-size: 30rpx;
              }
            }

            & > text {
              font-weight: 400;
              font-size: 20rpx;
              color: #666666;
              line-height: 28rpx;
              margin-top: 8rpx;
            }
          }

          .c_info {
            position: absolute;
            left: 204rpx;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            align-items: flex-start;

            .xz {
              font-weight: 400;
              font-size: 22rpx;
              color: #333333;
              line-height: 32rpx;
            }

            .c_box {
              font-weight: 400;
              font-size: 20rpx;
              color: #666666;
              line-height: 28rpx;
              margin-top: 6rpx;
            }

            .time {
              font-weight: 400;
              font-size: 20rpx;
              color: #ff575b;
              line-height: 28rpx;
              margin-top: 18rpx;
            }
          }

          .checkImg {
            position: absolute;
            right: 30rpx;
            top: 50%;
            transform: translateY(-50%);
            width: 116rpx;
            height: 48rpx;
          }
        }
      }

      .btn {
        padding: 20rpx 30rpx;
        // box-shadow: 0rpx -4rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
        // background: #FFFFFF;

        button {
          width: 100%;
          height: 96rpx;
          background: linear-gradient(90deg, #ffa233 0%, #fb4c4c 100%);
          border-radius: 80rpx 80rpx 80rpx 80rpx;
          font-weight: bold;
          font-size: 32rpx;
          color: #ffffff;
          line-height: 96rpx;
        }
      }
    }

    .haibao {
      .canvas_content {
        width: 520rpx;
        height: auto;
        background: #ffffff;
        box-sizing: border-box;
        // background-color: #F5F5F5;
        border-radius: 20rpx;
        margin: 0 auto 32rpx;
        & > image {
          width: 100%;
          height: 100%;
          border-radius: 20rpx;
        }
      }
      .hb_b {
        background-color: #f5f5f5;
        border-radius: 16rpx 16rpx 0 0;

        padding-bottom: calc(constant(safe-area-inset-bottom));
        padding-bottom: calc(env(safe-area-inset-bottom));
      }
    }

    .jiantou {
      width: 100vw;
      height: 100vh;
      background-color: rgba(0, 0, 0, 0.6);
      position: fixed;
      top: 0;
      left: 0;
      z-index: 999999;
      image {
        width: 300rpx;
        height: 400rpx;
        position: absolute;
      }
      view {
        position: absolute;
        top: 500rpx;
        right: 300rpx;
        color: #ff0000;
        font-size: 48rpx;
        font-weight: bold;
      }
    }

    /deep/ .hbpopup {
      background-color: transparent !important;
      padding-bottom: 0 !important;
    }
  }

  .tab_2 {
    padding-top: 18rpx;
    .item {
      display: flex;
      justify-content: space-between;
      padding: 22rpx;
      box-sizing: border-box;
      border-bottom: 2rpx solid #eeeeee;
      .left {
        display: flex;
        align-items: center;
        image {
          width: 88rpx;
          height: 88rpx;
          border-radius: 50%;
        }
        .user {
          display: flex;
          flex-direction: column;
          justify-content: center;
          padding-left: 20rpx;
          .name {
            font-weight: bold;
            font-size: 28rpx;
            color: #000000;
            line-height: 40rpx;
          }
          .phoneNumber {
            font-weight: 400;
            font-size: 24rpx;
            color: #818181;
            line-height: 34rpx;
            margin-top: 4rpx;
          }
        }
      }
      .right {
        display: flex;
        flex-direction: column;
        justify-content: center;
        .time {
          font-weight: 400;
          font-size: 24rpx;
          color: #818181;
          line-height: 34rpx;
        }
        .status {
          font-weight: 400;
          font-size: 28rpx;
          color: #e72a2a;
          line-height: 40rpx;
          margin-top: 4rpx;
        }
      }
    }
  }

  .tab_3 {
    padding: 40rpx 0 0;
    font-weight: 400;
    font-size: 32rpx;
    color: #333333;
    line-height: 40rpx;
  }
}
</style>
